#include<iostream>
using namespace std;
const int N = 1e5 + 10;
int arr[N];
int n;
int fun(int l, int r)
{
	if (l == r) {
	//	cout << "if(l==r)" << "            r" << endl;
		return arr[l];
	}
	int mid = (l + r) >> 1;
	int sum1 = fun(l, mid);
	int sum2 = fun(mid + 1, r);
	int ls = 0, lmax = 0;
	int rs = 0, rmax = 0;
	for (int i = mid; i >= l; i--) {
		ls += arr[i];
		lmax = max(lmax, ls);
	}
	for (int i = mid + 1; i <= r; i++) {
		rs += arr[i];																			
		rmax = max(rmax, rs);
	}
	int sum3 = rmax + lmax;
	return max(sum3, max(sum1, sum2));
}
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	int ans = fun(0, n - 1);
	cout << ans << endl;
	return 0;
}